Wrap Text function is frequently needed when the excel text exceeds a column width, and some data cannot be shown. In order to display the text in a full sight, people are required to wrap the cell. Using the wrap function, people can display long lines of data in one column instead of letting them go across the screen that is typical if the text does not fit the cell.
Spire.XLS, as a professional Excel component, allows developers to realize multiple functions of Excel Text in various ways, wrap text is just one small feature. This text aims at introducing a simple method to wrap excel text with C#,VB.NET.
Please follow the procedure below
Spire.XLS, as a professional Excel component, allows developers to realize multiple functions of Excel Text in various ways, wrap text is just one small feature. This text aims at introducing a simple method to wrap excel text with C#,VB.NET.
Please follow the procedure below
Procedure:
First, create a new workbook.
Second, write text in excel and wrap the text.
In this step, except wrapping excel text, I also unwrap the excel data to make comparison. Finally, I set text color to beautify the text.
At last, save the project and preview the effect.
Main Code:
First, create a new workbook.
Second, write text in excel and wrap the text.
In this step, except wrapping excel text, I also unwrap the excel data to make comparison. Finally, I set text color to beautify the text.
At last, save the project and preview the effect.
Main Code:
C# Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using Spire.Xls;
namespace wrap
{
class Program
{
static void Main(string[] args)
{
//Create a new workbook;
Workbook workbook = new Workbook();
Worksheet sheet = workbook.Worksheets[0];
//Wrap the excel text;
sheet.Range["A1"].Text = http://www.everlasting129.weebly.com;
sheet.Range["A1"].Style.WrapText = true;
sheet.Range["B1"].Text = http://www.e-iceblue.com;
sheet.Range["B1"].Style.WrapText= true;
//Unwrap the excel text;
sheet.Range["A2"].Text = http://www.e-iceblue.com/Introduce/spire-office-for-net.html;
sheet.Range["A2"].Style.WrapText= false;
sheet.Range["B2"].Text = http://www.e-iceblue.com/Download/download-office-for-net-now.html;
sheet.Range["B2"].Style.WrapText = false;
//set the text color of Range["A1:B1"]
sheet.Range["A1:B1"].Style.Font.Color = Color.Green;
//set the text color of Range["A2:B2"]
sheet.Range["A2:B2"].Style.Font.Color = Color.Blue;
// Save the project;
workbook.SaveToFile("sample.xls", ExcelVersion.Version97to2003);
System.Diagnostics.Process.Start(workbook.FileName);
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using Spire.Xls;
namespace wrap
{
class Program
{
static void Main(string[] args)
{
//Create a new workbook;
Workbook workbook = new Workbook();
Worksheet sheet = workbook.Worksheets[0];
//Wrap the excel text;
sheet.Range["A1"].Text = http://www.everlasting129.weebly.com;
sheet.Range["A1"].Style.WrapText = true;
sheet.Range["B1"].Text = http://www.e-iceblue.com;
sheet.Range["B1"].Style.WrapText= true;
//Unwrap the excel text;
sheet.Range["A2"].Text = http://www.e-iceblue.com/Introduce/spire-office-for-net.html;
sheet.Range["A2"].Style.WrapText= false;
sheet.Range["B2"].Text = http://www.e-iceblue.com/Download/download-office-for-net-now.html;
sheet.Range["B2"].Style.WrapText = false;
//set the text color of Range["A1:B1"]
sheet.Range["A1:B1"].Style.Font.Color = Color.Green;
//set the text color of Range["A2:B2"]
sheet.Range["A2:B2"].Style.Font.Color = Color.Blue;
// Save the project;
workbook.SaveToFile("sample.xls", ExcelVersion.Version97to2003);
System.Diagnostics.Process.Start(workbook.FileName);
}
}
}
VB.NET Code:
Imports System;
Imports System.Collections.Generic;
Imports System.Linq;
Imports System.Text;
Imports System.Drawing;
Imports Spire.Xls;
Namespace wrap
Friend Class Program
Shared Sub Main(ByVal args() As String)
‘ Create a new workbook;
Dim workbook As New Workbook();
Dim worksheet As Worksheet = workbook.Worksheets(0);
‘Wrap the excel text;
sheet.Range["A1"].Text = http://www.everlasting129.weebly.com;
sheet.Range["A1"].Style.WrapText = true;
sheet.Range["B1"].Text = http://www.e-iceblue.com;
sheet.Range["B1"].Style.WrapText= true;
‘Unwrap the excel text;
sheet.Range["A2"].Text = http://www.e-iceblue.com/Introduce/spire-office-for-net.html;
sheet.Range["A2"].Style.WrapText= false;
sheet.Range["B2"].Text = http://www.e-iceblue.com/Download/download-office-for-net-now.html;
sheet.Range["B2"].Style.WrapText = false;
‘set the text color of Range["A1:B1"]
sheet.Range["A1:B1"].Style.Font.Color = Color.Green;
‘set the text color of Range["A2:B2"]
sheet.Range["A2:B2"].Style.Font.Color = Color.Blue;
‘Save the project;
workbook.SaveToFile("sample.xls", ExcelVersion.Version97to2003);
System.Diagnostics.Process.Start(workbook.FileName);
End Sub
End Class
End Namespace
Preview
Imports System;
Imports System.Collections.Generic;
Imports System.Linq;
Imports System.Text;
Imports System.Drawing;
Imports Spire.Xls;
Namespace wrap
Friend Class Program
Shared Sub Main(ByVal args() As String)
‘ Create a new workbook;
Dim workbook As New Workbook();
Dim worksheet As Worksheet = workbook.Worksheets(0);
‘Wrap the excel text;
sheet.Range["A1"].Text = http://www.everlasting129.weebly.com;
sheet.Range["A1"].Style.WrapText = true;
sheet.Range["B1"].Text = http://www.e-iceblue.com;
sheet.Range["B1"].Style.WrapText= true;
‘Unwrap the excel text;
sheet.Range["A2"].Text = http://www.e-iceblue.com/Introduce/spire-office-for-net.html;
sheet.Range["A2"].Style.WrapText= false;
sheet.Range["B2"].Text = http://www.e-iceblue.com/Download/download-office-for-net-now.html;
sheet.Range["B2"].Style.WrapText = false;
‘set the text color of Range["A1:B1"]
sheet.Range["A1:B1"].Style.Font.Color = Color.Green;
‘set the text color of Range["A2:B2"]
sheet.Range["A2:B2"].Style.Font.Color = Color.Blue;
‘Save the project;
workbook.SaveToFile("sample.xls", ExcelVersion.Version97to2003);
System.Diagnostics.Process.Start(workbook.FileName);
End Sub
End Class
End Namespace
Preview
Note: 1. In order to realize the task,Spire.Xls is added to the system. You can Freely Download Spire.XLS.
2. When using Visual Studio, please choose .NET Framework 4 as the Target Framework.
3. Excel Forum is for asking questions and solving problems, you can leave your questions on it and there are professionals ready to help you.
Spire.Office
Spire.Office for .NET is a compilation of every .NET component offered by e-iceblue. It includes Spire.Doc, Spire.PDFViewer, Spire.XLS, Spire.PDF and Spire.DataExport. Spire.Office contains the most up-to-date versions of the components above. Using Spire.Office for .NET developers can create a wide range of applications.
Source
2. When using Visual Studio, please choose .NET Framework 4 as the Target Framework.
3. Excel Forum is for asking questions and solving problems, you can leave your questions on it and there are professionals ready to help you.
Spire.Office
Spire.Office for .NET is a compilation of every .NET component offered by e-iceblue. It includes Spire.Doc, Spire.PDFViewer, Spire.XLS, Spire.PDF and Spire.DataExport. Spire.Office contains the most up-to-date versions of the components above. Using Spire.Office for .NET developers can create a wide range of applications.
Source